package com.joker.web.controller.orange;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.joker.common.annotation.RepeatSubmit;
import com.joker.common.annotation.Log;
import com.joker.common.core.controller.BaseController;
import com.joker.common.core.domain.PageQuery;
import com.joker.common.core.domain.R;
import com.joker.common.core.validate.AddGroup;
import com.joker.common.core.validate.EditGroup;
import com.joker.common.enums.BusinessType;
import com.joker.common.utils.poi.ExcelUtil;
import com.joker.orange.domain.vo.ApplicationCenterVo;
import com.joker.orange.domain.bo.ApplicationCenterBo;
import com.joker.orange.service.IApplicationCenterService;
import com.joker.common.core.page.TableDataInfo;

/**
 * 应用信息
 *
 * @author Joker
 * @date 2024-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/advertising/application")
public class ApplicationCenterController extends BaseController {

    private final IApplicationCenterService iApplicationCenterService;

    /**
     * 查询应用信息列表
     */
    @SaCheckPermission("advertising:application:list")
    @GetMapping("/list")
    public TableDataInfo<ApplicationCenterVo> list(ApplicationCenterBo bo, PageQuery pageQuery) {
        return iApplicationCenterService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出应用信息列表
     */
    @SaCheckPermission("advertising:application:export")
    @Log(title = "应用信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ApplicationCenterBo bo, HttpServletResponse response) {
        List<ApplicationCenterVo> list = iApplicationCenterService.queryList(bo);
        ExcelUtil.exportExcel(list, "应用信息", ApplicationCenterVo.class, response);
    }

    /**
     * 获取应用信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("advertising:application:query")
    @GetMapping("/{id}")
    public R<ApplicationCenterVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iApplicationCenterService.queryById(id));
    }

    /**
     * 新增应用信息
     */
    @SaCheckPermission("advertising:application:add")
    @Log(title = "应用信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ApplicationCenterBo bo) {
        return toAjax(iApplicationCenterService.insertByBo(bo));
    }

    /**
     * 修改应用信息
     */
    @SaCheckPermission("advertising:application:edit")
    @Log(title = "应用信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ApplicationCenterBo bo) {
        return toAjax(iApplicationCenterService.updateByBo(bo));
    }

    /**
     * 删除应用信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("advertising:application:remove")
    @Log(title = "应用信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iApplicationCenterService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
